{% extends 'base.html' %}

{% block title %}创建订单 - 花店订单系统{% endblock %}

{% block content %}
<div class="container">
    <div class="row">
        <div class="col-md-8 offset-md-2">
            <div class="card">
                <div class="card-header">
                    <h3 class="card-title">创建订单</h3>
                </div>
                <div class="card-body">
                    <div class="row mb-4">
                        <div class="col-md-4">
                            {% if product.image %}
                                <img src="{{ product.image.url }}" class="img-fluid rounded" alt="{{ product.name }}">
                            {% else %}
                                <img src="https://via.placeholder.com/200" class="img-fluid rounded" alt="默认图片">
                            {% endif %}
                        </div>
                        <div class="col-md-8">
                            <h4>{{ product.name }}</h4>
                            <p>{{ product.description }}</p>
                            <p><strong>单价：</strong>¥{{ product.price }}</p>
                            <p><strong>库存：</strong>{{ product.stock }}件</p>
                        </div>
                    </div>

                    <form method="post" action="{% url 'orders:create_order' product.id %}">
                        {% csrf_token %}
                        <div class="mb-3">
                            <label for="quantity" class="form-label">购买数量</label>
                            <input type="number" class="form-control" id="quantity" name="quantity" 
                                   min="1" max="{{ product.stock }}" value="1" required>
                        </div>
                        <div class="mb-3">
                            <label for="address" class="form-label">收货地址</label>
                            <textarea class="form-control" id="address" name="address" rows="3" required></textarea>
                        </div>
                        <div class="mb-3">
                            <label for="phone" class="form-label">联系电话</label>
                            <input type="tel" class="form-control" id="phone" name="phone" required>
                        </div>
                        <div class="d-grid gap-2">
                            <button type="submit" class="btn btn-primary">提交订单</button>
                            <a href="{% url 'products:product_detail' product.id %}" class="btn btn-secondary">返回商品详情</a>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %} 